# !/usr/bin/env python
# coding=utf-8
# @Time    : 2018/7/15 8:32
# @Author  : 6imensiva
# @Site    : https://gitee.com/dimensiva/rpc_dao.git
# @File    : car_insurance.py
# @Software: PyCharm
# @Version: 2.7.5
from . import Session
from .models import TCarInsurance


def add_car_insurance_info(*args):
	session = Session()
	try:
		session.execute(
			TCarInsurance.__table__.insert(),
			{'licenseNo': args[0],
			 'frameNo': args[1],
			 'engineNo': args[2],
			 'biOrderNumber': args[3],
			 'ciOrderNumber': args[4],
			 'biDate': args[5],
			 'ciDate': args[6],
			 'insuranceUnit': args[7],
			 'insuranceContent': args[8]
			 }
		)
		session.commit()
	except Exception:
		session.rollback()


def get_car_insurance_info(license, frame_no, engine_no):
	session = Session()
	return session.query(TCarInsurance).filter_by(licenseNo=license, frameNo=frame_no, engineNo=engine_no).\
		order_by(TCarInsurance.biDate.desc()).first()

